package com.yc.thread.basic;


@FunctionalInterface
interface Action<T> {
    void execute(T t);
}

/**
 * concurrent
 * 函数式编程语法的一个理解
 *
 * @author zwei
 * @create 2024-07-15 19:08
 */
public class Test10_function {
    public static void main(String[] args) {
        Action action3 = new MyAction();
        action3.execute("hello");
        //外部类
        Action action4 = new Action() {
            @Override
            public void execute(Object o) {
                System.out.println(o);
            }
        };
        action4.execute("你好啊");


        //lambda语法
        Action action2 = (t) -> {
            //处理
            System.out.println(t);
        };
        action2.execute("bye");

        //直接绑定
        Action action = System.out::println;  //System.out.println(1);
        action.execute("hello world");

        //作为参数用
        test(System.out::println, "...");
    }

    static void test(Action action, String str) {
        action.execute(str);
    }
}

class MyAction implements Action {

    @Override
    public void execute(Object o) {
        System.out.println(o);
    }
}
